using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the Summary class.
	/// </summary>
    [Serializable]
	public partial class SummaryCollection : ActiveList<Summary, SummaryCollection>
	{	   
		public SummaryCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>SummaryCollection</returns>
		public SummaryCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Summary o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the SUMMARY table.
	/// </summary>
	[Serializable]
	public partial class Summary : ActiveRecord<Summary>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Summary()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Summary(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Summary(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Summary(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("SUMMARY", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarId = new TableSchema.TableColumn(schema);
				colvarId.ColumnName = "ID";
				colvarId.DataType = DbType.Int64;
				colvarId.MaxLength = 0;
				colvarId.AutoIncrement = true;
				colvarId.IsNullable = false;
				colvarId.IsPrimaryKey = true;
				colvarId.IsForeignKey = false;
				colvarId.IsReadOnly = false;
				colvarId.DefaultSetting = @"";
				colvarId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarId);
				
				TableSchema.TableColumn colvarUserID = new TableSchema.TableColumn(schema);
				colvarUserID.ColumnName = "UserID";
				colvarUserID.DataType = DbType.Int32;
				colvarUserID.MaxLength = 0;
				colvarUserID.AutoIncrement = false;
				colvarUserID.IsNullable = false;
				colvarUserID.IsPrimaryKey = false;
				colvarUserID.IsForeignKey = false;
				colvarUserID.IsReadOnly = false;
				colvarUserID.DefaultSetting = @"";
				colvarUserID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserID);
				
				TableSchema.TableColumn colvarMediaType = new TableSchema.TableColumn(schema);
				colvarMediaType.ColumnName = "Media Type";
				colvarMediaType.DataType = DbType.String;
				colvarMediaType.MaxLength = 50;
				colvarMediaType.AutoIncrement = false;
				colvarMediaType.IsNullable = true;
				colvarMediaType.IsPrimaryKey = false;
				colvarMediaType.IsForeignKey = false;
				colvarMediaType.IsReadOnly = false;
				colvarMediaType.DefaultSetting = @"";
				colvarMediaType.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMediaType);
				
				TableSchema.TableColumn colvarInsertions = new TableSchema.TableColumn(schema);
				colvarInsertions.ColumnName = "Insertions";
				colvarInsertions.DataType = DbType.Int64;
				colvarInsertions.MaxLength = 0;
				colvarInsertions.AutoIncrement = false;
				colvarInsertions.IsNullable = true;
				colvarInsertions.IsPrimaryKey = false;
				colvarInsertions.IsForeignKey = false;
				colvarInsertions.IsReadOnly = false;
				colvarInsertions.DefaultSetting = @"";
				colvarInsertions.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInsertions);
				
				TableSchema.TableColumn colvarInvestment = new TableSchema.TableColumn(schema);
				colvarInvestment.ColumnName = "Investment";
				colvarInvestment.DataType = DbType.Int64;
				colvarInvestment.MaxLength = 0;
				colvarInvestment.AutoIncrement = false;
				colvarInvestment.IsNullable = true;
				colvarInvestment.IsPrimaryKey = false;
				colvarInvestment.IsForeignKey = false;
				colvarInvestment.IsReadOnly = false;
				colvarInvestment.DefaultSetting = @"";
				colvarInvestment.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInvestment);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("SUMMARY",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("Id")]
		[Bindable(true)]
		public long Id 
		{
			get { return GetColumnValue<long>(Columns.Id); }
			set { SetColumnValue(Columns.Id, value); }
		}
		  
		[XmlAttribute("UserID")]
		[Bindable(true)]
		public int UserID 
		{
			get { return GetColumnValue<int>(Columns.UserID); }
			set { SetColumnValue(Columns.UserID, value); }
		}
		  
		[XmlAttribute("MediaType")]
		[Bindable(true)]
		public string MediaType 
		{
			get { return GetColumnValue<string>(Columns.MediaType); }
			set { SetColumnValue(Columns.MediaType, value); }
		}
		  
		[XmlAttribute("Insertions")]
		[Bindable(true)]
		public long? Insertions 
		{
			get { return GetColumnValue<long?>(Columns.Insertions); }
			set { SetColumnValue(Columns.Insertions, value); }
		}
		  
		[XmlAttribute("Investment")]
		[Bindable(true)]
		public long? Investment 
		{
			get { return GetColumnValue<long?>(Columns.Investment); }
			set { SetColumnValue(Columns.Investment, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varUserID,string varMediaType,long? varInsertions,long? varInvestment)
		{
			Summary item = new Summary();
			
			item.UserID = varUserID;
			
			item.MediaType = varMediaType;
			
			item.Insertions = varInsertions;
			
			item.Investment = varInvestment;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(long varId,int varUserID,string varMediaType,long? varInsertions,long? varInvestment)
		{
			Summary item = new Summary();
			
				item.Id = varId;
			
				item.UserID = varUserID;
			
				item.MediaType = varMediaType;
			
				item.Insertions = varInsertions;
			
				item.Investment = varInvestment;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn IdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn UserIDColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn MediaTypeColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn InsertionsColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn InvestmentColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string Id = @"ID";
			 public static string UserID = @"UserID";
			 public static string MediaType = @"Media Type";
			 public static string Insertions = @"Insertions";
			 public static string Investment = @"Investment";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
